package top.kaoshanji.r2ch07d;

import org.aopalliance.intercept.MethodInterceptor;
import org.aopalliance.intercept.MethodInvocation;

/**
 * 代码清单-r2ch07d-237页a：定义一个环绕增强
 * @author kaoshanji
 * ^_^
 * create time 2025/5/7 17:35
 */
public class GreetingAround implements MethodInterceptor {

    @Override
    public Object invoke(MethodInvocation methodInvocation) throws Throwable {

        Object[] args = methodInvocation.getArguments(); // 目标方法入参
        String clientName = (String) args[0];

        System.out.println("...Around....欢迎光临！Mr." + clientName + "...."); // 在目标方法执行前调用

        Object obj = methodInvocation.proceed(); // 通过反射机制调用目标方法

        System.out.println("...Around....希望下次再来！"); // 在目标方法执行后调用

        return obj;
    }

}
